package com.yk.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yk.common.annotation.Log;
import com.yk.common.enums.BusinessType;
import com.yk.points.domain.PointsUser;
import com.yk.points.service.IPointsUserService;
import com.yk.common.core.controller.BaseController;
import com.yk.common.core.domain.AjaxResult;
import com.yk.common.utils.poi.ExcelUtil;
import com.yk.common.core.page.TableDataInfo;
import org.springframework.stereotype.Controller;

/**
 * 用户积分Controller
 * 
 * @author xufei
 * @date 2025-04-28
 */
@Controller
@RequestMapping("/points/pointsUser")
public class PointsUserController extends BaseController
{
    private String prefix = "points/pointsUser";

    @Autowired
    private IPointsUserService pointsUserService;

    @RequiresPermissions("points:pointsUser:view")
    @GetMapping()
    public String pointsUser()
    {
        return prefix + "/pointsUser";
    }

    /**
     * 查询用户积分列表
     */
    @RequiresPermissions("points:pointsUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PointsUser pointsUser)
    {
        startPage();
        List<PointsUser> list = pointsUserService.selectPointsUserList(pointsUser);
        return getDataTable(list);
    }

    /**
     * 导出用户积分列表
     */
    @RequiresPermissions("points:pointsUser:export")
    @Log(title = "用户积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PointsUser pointsUser)
    {
        List<PointsUser> list = pointsUserService.selectPointsUserList(pointsUser);
        ExcelUtil<PointsUser> util = new ExcelUtil<PointsUser>(PointsUser.class);
        return util.exportExcel(list, "用户积分数据");
    }

    /**
     * 新增用户积分
     */
    @RequiresPermissions("points:pointsUser:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户积分
     */
    @RequiresPermissions("points:pointsUser:add")
    @Log(title = "用户积分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PointsUser pointsUser)
    {
        return toAjax(pointsUserService.insertPointsUser(pointsUser));
    }

    /**
     * 修改用户积分
     */
    @RequiresPermissions("points:pointsUser:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PointsUser pointsUser = pointsUserService.selectPointsUserById(id);
        mmap.put("pointsUser", pointsUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户积分
     */
    @RequiresPermissions("points:pointsUser:edit")
    @Log(title = "用户积分", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PointsUser pointsUser)
    {
        return toAjax(pointsUserService.updatePointsUser(pointsUser));
    }

    /**
     * 删除用户积分
     */
    @RequiresPermissions("points:pointsUser:remove")
    @Log(title = "用户积分", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pointsUserService.deletePointsUserByIds(ids));
    }
}
